//using LitJson;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class StorageManager : MonoSingleton<StorageManager>
{
    public override void Init()
    {
        base.Init();
    }
    public void Save<T>(string path, T data)
    {
        try
        {
            string text = JsonUtility.ToJson(data);
            PlayerPrefs.SetString(path, text);
            PlayerPrefs.Save();
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
            throw;
        }

    }
    public void Load<T>(string path, ref T data)
    {
        if (!PlayerPrefs.HasKey(path))
        {
            Debug.LogError(path + "当前无数据");
            return;
        }
        try
        {
            string jsonData = PlayerPrefs.GetString(path);
            data = JsonUtility.FromJson<T>(jsonData);
        }
        catch (Exception e)
        {
            Debug.Log(e.Message);
            throw;
        }
    }
}
